import getvalue2
import  wxchat;
import tkinter as tk
import argparse
from PIL import Image
import time
import os
from datetime import datetime
import uuid
import addnodetofile



def generate_random_id():
    # 生成一个 UUID
    random_uuid = uuid.uuid4()
    # 将 UUID 转换为十六进制字符串并取前 16 位
    return random_uuid.hex[:16]


parser = argparse.ArgumentParser(description='处理图片及相关信息的脚本')
parser.add_argument('-imagepath', type=str, required=True, help='图片的路径')
parser.add_argument('-msg', type=str, required=True, help='用户的输入信息')

args = parser.parse_args()
image_path = args.imagepath
user_msg = args.msg




# 笔记文件夹
wikipath="E:\\wiki\\wikiob\\a2\\全新"

dic={
    'beforewidth':0,
    "beforeinput":"",
    "windowroot":None
    }

save_folder = f"{wikipath}\\_files"
if not os.path.exists(save_folder):
    os.makedirs(save_folder)

##.py

print('image_path===>',image_path)
img = Image.open(image_path)
getvalue2.setvalue2txt(user_msg)


# 发送到文档笔记
print('------------发送到文档笔记-----------------')
list1 = user_msg.split('#')
list2 = [s for s in list1 if s.strip()]
firsttag = list2[0]
# 获取第一个 然后附件名称.canvas保存起来
file_name = str(int(time.time())) + ".png"
file_path = os.path.join(save_folder, file_name)
img.save(file_path)
print(f"已成功将图片保存到 {file_path}")

tagstr = f"{user_msg}#{datetime.now().strftime('%Y年%m月%d日')}"
markdown=f"{tagstr}\n![[_files/{file_name}]]\n\n\n"
_dic = {
    "id": generate_random_id(),
    "type": "text",
    "text": markdown,
    "styleAttributes": {},
    "x": -220,
    "y": 140,
    "width": img.width,
    "height": img.height
}
print("_dic", _dic);
addnodetofile.add_node_to_file(_dic, f"{firsttag}.canvas", wikipath)


